
import * as _ from 'lodash';

var IgnitionKey= {
    keyOff : "0",
    keyAcc : "0",
    keyOn  : "0",
    keyStart : "1",
    runStatus : "1",
    ignCount :"0"
    
}
// let VehicleDescription={
//     vehType : "Magoton"
// }
var SensorInstall= {
    In1_num0 : "1",
    In1_num1 : "1",
    In1_num2 : "1"
}
var SensorFault={
     In1_num0 : "1",
     In1_num1 : "1",
     In1_num2 : "1"
}
var InputPara={
    IgnitionKey,
   // VehicleDescription,
    SensorInstall,
    SensorFault
}
var IgnSigOut={
    Out2Dash_IgnSig: "0"
}
class KeySwitch{
    private keyOff;
    private keyOn;
    private keyStart;
    private keyAcc;
    private runStatus;
    private ignCount=50;
    public  ignSigOut;
  //   public getKeyOff(){
  //       return this.keyOff;
  //   }
  //   public setKeyOff(keyOff){
  //       this.keyOff=keyOff;
  //   }
  //   public getKeyAcc(){
  //       return this.keyAcc;
  //   }
  //   public setKeyAcc(keyAcc){
  //       this.keyAcc=keyAcc;
  //   }
  //   public getKeyOn(){
  //       return this.keyOn;
  //   }
  //   public setKeyOn(keyOn){
  //       this.keyOn=keyOn;
  // }
  //   public getKeyStart(){
  //       return this.keyStart;
  //   }
  //   public setKeyStart(keyStart){
  //       this.keyStart=keyStart;
  //   }
  //   public getRunStatus(){
  //       return this.runStatus;
  //   }
  //   public setRunStatus(runStatus){
  //       this.runStatus=runStatus;
  //   }
    public keySwtLogic(keyOff,keyAcc,keyOn,keyStart){
               // this.keyOff=keyOff;
               // this.keyAcc=keyAcc;
               // this.keyOn=keyOn;
               // this.keyStart=keyStart;
               // this.runStatus=runStatus;
              // console.log(this.keyStart);
        var keySwitchIn=(function(){

            if(keyOff=="1"){
                return "0";
            }else if(keyAcc=="1"){
                return "1";
            }else if(keyOn=="1"){
                return "2";
            }else if(keyStart=="1"){
                
                return "3";
            }
          
        })();
       var IgnKeyCount=function(){
           var num=0;
           if(keyStart=="1"){
               for(let i=0;i<100;i++){
                    num=num+1;
               }
                return num;
            }
          }
          var num=IgnKeyCount();
          console.log(num);
        return keySwitchIn;
    }
}
var modelInput=new KeySwitch();
// modelInput.setKeyOff(InputPara.IgnitionKey.keyOff);
// modelInput.setKeyAcc(InputPara.IgnitionKey.keyAcc);
// modelInput.setKeyOn(InputPara.IgnitionKey.keyOn);
// modelInput.setKeyStart(InputPara.IgnitionKey.keyStart);
// modelInput.setRunStatus(InputPara.IgnitionKey.runStatus);
//console.log(modelInput.getKeyStart());
var keyIn=modelInput.keySwtLogic(InputPara.IgnitionKey.keyOff,InputPara.IgnitionKey.keyAcc,InputPara.IgnitionKey.keyOn,InputPara.IgnitionKey.keyStart);
//console.log(IgnSigOut.Out2Dash_IgnSig);

//抽象策略类
interface KeyStrategy{
        keyLogic();
}
//策略实现类
class KeyOFF implements KeyStrategy{
        keyLogic(){
        console.log(111);
        }
}
class KeyACC implements KeyStrategy{
        keyLogic(){
        console.log(222);
        }
}
class KeyON implements KeyStrategy{
        keyLogic(){
        console.log(333);
        }
}
class KeySTART implements KeyStrategy{
    keyLogic(){
        console.log(444);
        var num=0;
        if(InputPara.IgnitionKey.runStatus=="1"){
            for (let i = 0; i < 10 ; i++) {
                setTimeout(function() {
                   
                    //console.log(num);
                    //console.log(i);
                    return i;
                }, 100*i);
                   num=i;  
          //   console.log(num);
        
            }
            
           return 666;
        }else{
            return 2;
        }
    }
}
//环境类
class KeyContext{
    private keystrategy:KeyStrategy ;
    constructor(keystrategy:KeyStrategy){
            this.keystrategy = keystrategy;
    }
    public setStrategy(keystrategy:KeyStrategy){
            this.keystrategy = keystrategy;
            console.log(555);
    }
    public keyLogic(){
            return this.keystrategy.keyLogic();
   }
}

var context = new KeyContext(new KeyOFF());
    context.keyLogic();
if(keyIn=="1"){
    context.setStrategy(new KeyACC());
    context.keyLogic();
}else if(keyIn=="2"){
    context.setStrategy(new KeyON());
    context.keyLogic();
}else if(keyIn=="3"){
     context.setStrategy(new KeySTART());
     IgnSigOut.Out2Dash_IgnSig=context.keyLogic();
}
    console.log(IgnSigOut.Out2Dash_IgnSig);
